<template>
  <a-modal
      v-model:visible="visible"
      title="配置修改"
      ok-text="提交修改"
      :mask-closable="false"
      @cancel="handleCancel"
      @before-ok="handleSubmit"
  >
    <a-form :model="form" style="min-width: 450px">
      <a-form-item field="remark" label="备注">
        <a-textarea
            v-model="form.remark"
            placeholder="备注，不能为空"
            allow-clear
            :max-length="125"
            show-word-limit
            style="height: 95px"
        />
      </a-form-item>
      <a-form-item label="注意">
        <b style="font-size: 14px;color: red;">网关服务将会重启</b>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script setup>
import {Notification} from "@arco-design/web-vue";
import apiAll from "@/api/apiAll.js";
import {ref} from "vue";

const emits = defineEmits(["success"]);
const form = ref({});
const visible = ref(false);
const handleSubmit = (done) => {
  if(form.value.remark===''){
    done(false);
    Notification.error('备注不能为空')
    return
  }
  apiAll.configApi.set(form.value)
      .then((res) => {
        Notification.success('配置修改成功')
        setTimeout(() => {
          visible.value = false;
          emits("success");
          done();
        }, 500);
      })
      .catch(() => {
        setTimeout(() => {
          done(false);
        }, 1000);
      });
};

const handleCancel = () => {
  visible.value = false;
};

const show = (xml) => {
  form.value.xml = xml;
  form.value.type = '';
  form.value.remark = ''
  visible.value = true;
};

defineExpose({show});
</script>
